
package com.be.beadmin.project.repository;

import com.be.beadmin.project.entity.PlanStage;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @author zjm
* @date 2023-06-18
**/
public interface PlanStageRepository extends JpaRepository<PlanStage, String>, JpaSpecificationExecutor<PlanStage> {

    PlanStage findPlanStageByIdAndDelete(String id, Integer delete);

    PlanStage findPlanStageByPlanIdAndStageNameAndDelete(String planId,String stageName, Integer delete);

    List<PlanStage> findPlanStagesByPlanIdAndDeleteOrderByStageSort(String id, Integer delete);

    List<PlanStage> findPlanStagesByPlanIdAndDeleteOrderByStageSortDesc(String id, Integer delete);

    PlanStage findPlanStageById(String id);

    @Modifying
    @Transactional
    @Query(value = "update t_pm_plan_stage ps set ps.is_delete = ?1 where ps.plan_id in ?2 and ps.is_delete = ?3",nativeQuery = true)
    void deletePlanStageByPlanIdInAndDelete(int deleted,List<String> planId,int noDelete);


    @Modifying
    @Transactional
    @Query(value = "update t_pm_plan_stage ps set ps.is_delete = ?1 where ps.plan_id = ?2 and ps.is_delete = ?3",nativeQuery = true)
    void deletePlanStageByPlanIdAndDelete(int deleted,String planId,int noDelete);

}